home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / DX Clock 1.31 / DX Clockƒ / DX Clock cdev.p next >
Encoding:
Text File  |  1994-01-05  |  3.9 KB  |  182 lines  |  [TEXT/PJMM]

  1. unit DXClock;
  2.  
  3. { cdev used to set the params of the init DX Clock }
  4. {  started  August 15 1991 }
  5. { creator : DXCL  }
  6. { V1.0d1 }
  7.  
  8. { released in the public domain january 5 1994 }
  9.  
  10. interface
  11.  
  12.     uses
  13.         Tools, Globals, Prefs;
  14.  
  15.     function Main (message, item, numItems, CPanelID: Integer; theEvent: EventRecord; cdevValue: LongInt; CPDialog: DialogPtr): LongInt;
  16.  
  17. implementation
  18.  
  19.     procedure IGetRect (ourHandle: SampleHdl; item: Integer; var itemRect: Rect);
  20.     Forward;
  21.     procedure HitSample (ourHandle: SampleHdl; item: Integer; theEvent: EventRecord);
  22.     Forward;
  23.     function InitSample (CPDialog: DialogPtr; numItems: Integer): LongInt;
  24.     Forward;
  25.     function IGetCtlHand (ourHandle: SampleHdl; item: Integer): ControlHandle;
  26.     Forward;
  27.  
  28.     function Main;
  29.  
  30.         var
  31.             ourHandle: sampleHdl;
  32.             storageExpected: Boolean;
  33.             theStr: Str255;
  34.             box: Rect;
  35.             saveClip, theRgn: RgnHandle;
  36.             thePat: PatHandle;
  37.  
  38.     begin
  39.  
  40.         storageExpected := not ((message = initDev) or (message = macDev));
  41.         if storageExpected and ((cdevValue = 0) or (cdevValue = cdevUnset)) then
  42.             cdevValue := 0
  43.         else
  44.             begin
  45.                 ourHandle := sampleHdl(cdevValue);
  46.                 case message of
  47.                     initDev: 
  48.                         begin
  49.                             cdevValue := InitSample(CPDialog, numItems);
  50.                             ourHandle := sampleHdl(cdevValue);
  51.                         end;
  52.                     closeDev: 
  53.                         if ourHandle <> nil then
  54.                             begin
  55.                                 DisposHandle(Handle(ourHandle));
  56.                                 cdevValue := 0;
  57.                                 ourHandle := nil;
  58.                             end;
  59.                     updateDev: 
  60.                         begin
  61.                             HLock(Handle(ourHandle));
  62.                             with ourHandle^^ do
  63.                                 begin
  64.                                     iGetRect(ourHandle, iPictRect, box);
  65.                                     MoveTo(box.right - StringWidth(vers) - 5, box.bottom - 4);
  66.                                     DrawString(vers);
  67. {UpdtDialog(CPDialog, CPDialog^.visRgn);}
  68. {ValidRect(CPDialog^.portRect);}
  69.                                 end;
  70.                             HUnlock(Handle(ourHandle));
  71.                         end;
  72.                     activDev: 
  73.                         begin
  74.                             HLock(Handle(ourHandle));
  75.                             HUnlock(Handle(ourHandle));
  76.                         end;
  77.                     deActivDev: 
  78.                         begin
  79.                             HLock(Handle(ourHandle));
  80.                             HUnlock(Handle(ourHandle));
  81.                         end;
  82.                     cursorDev: 
  83.                         SetCursor(QDGlobals^.arrow);
  84.                     hitDev: 
  85.                         HitSample(ourHandle, item - numItems, theEvent);
  86.  
  87.                     otherwise
  88.                         ;
  89.                 end; { Case }
  90.             end;
  91.         Main := cdevValue;
  92.  
  93.     end; { Main }
  94.  
  95. {----------------------------------------------------------------}
  96.  
  97.     procedure IGetRect (ourHandle: sampleHdl; item: Integer; var itemRect: Rect);
  98.  
  99.         var
  100.             itemHand: Handle;
  101.             itemType: Integer;
  102.  
  103.     begin
  104.  
  105.         with ourHandle^^ do
  106.             GetDItem(dlgPtr, item + dlgItems, itemType, itemHand, itemRect);
  107.  
  108.     end; { IGetRect }
  109.  
  110.     {----------------------------------------------------------------}
  111.  
  112.     function InitSample (CPDialog: DialogPtr; numItems: Integer): LongInt;
  113.  
  114.         var
  115.             ourHandle: sampleHdl;
  116.  
  117.     begin
  118.  
  119.         ourHandle := sampleHdl(NewHandle(sizeOf(SampleStorage)));
  120.         if ourHandle <> nil then
  121.             begin
  122.                 with ourHandle^^ do
  123.                     begin
  124.                         dlgPtr := CPDialog;
  125.                         dlgItems := numItems;
  126.                     end; { With }
  127.             end; { if }
  128.         InitSample := Ord4(ourHandle);
  129.  
  130.     end; { InitSample }
  131.  
  132.     {----------------------------------------------------------------}
  133.  
  134.     procedure HitSample (ourHandle: SampleHdl; item: Integer; theEvent: EventRecord);
  135.  
  136.         const
  137.             scrollConst = 5;
  138.             maxY = 202;
  139.  
  140.         var
  141.             thePoint: Point;
  142.             theDialog: DIalogPtr;
  143.             thePrefs: PrefHandle;
  144.  
  145.     begin
  146.  
  147.         thePoint := theEvent.where;
  148.         GlobalToLocal(thePoint);
  149.  
  150.         case item of
  151.             iSettings: 
  152.                 begin
  153.                     thePrefs := prefHandle(GetResource('DXCL', 1));
  154.                     DoPrefs(thePrefs);
  155.                     ReleaseResource(Handle(thePrefs));
  156.                 end;
  157.             otherwise
  158.                 ;
  159.         end; { Case }
  160.  
  161.     end; { HitSample }
  162.  
  163. {----------------------------------------------------------------}
  164.  
  165.     function IGetCtlHand (ourHandle: SampleHdl; item: Integer): ControlHandle;
  166.  
  167.         var
  168.             itemHand: Handle;
  169.             itemRect: Rect;
  170.             itemType: Integer;
  171.  
  172.     begin
  173.  
  174.         with ourHandle^^ do
  175.             GetDItem(dlgPtr, item + dlgItems, itemType, itemHand, itemRect);
  176.         IGetCtlHand := ControlHandle(itemHand)
  177.  
  178.     end; { IGetCtlHand }
  179.  
  180. {----------------------------------------------------------------}
  181.  
  182. end.